// 设置响应头的中间件
module.exports = async (ctx, next) => {
  const start = Date.now()
  ctx.set("Access-Control-Allow-Origin", "*")
  ctx.set("Access-Control-Allow-Methods", "OPTIONS,GET,PUT,POST,DELETE")
  ctx.set('Content-Type', 'application/json; charset=utf-8')
  
  await next()

  const end = Date.now()  //获得结束的时间戳
  const duration = end - start
  ctx.set('X-Response-Time', duration + 'ms')
}

